package com.gm.app.model;

import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.codehaus.jackson.map.annotate.JsonView;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;

import com.gm.app.data.PlaceDAO;
import com.gm.app.jackson.Views.Public;

@RooJavaBean
@RooToString
@RooEntity(table = "address", finders = { "findAddressesByDescription",
		"findAddressesByDescriptionLike" })
@DiscriminatorValue("address")
public class Address extends Geo {

	private Integer stNumber;

	private String complement;

	private String zip;

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.DETACH,
			CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "city_id", referencedColumnName = "id")
	
	private City city;

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.DETACH,
			CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "region_id", referencedColumnName = "id")
	
	private Region state;

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.DETACH,
			CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "country_id", referencedColumnName = "id")
	
	private Country country;

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.DETACH,
			CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "district_id", referencedColumnName = "id")
	
	private District district;

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.DETACH,
			CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "street_id", referencedColumnName = "id")
	
	private Street street;

	public String getImageAddress() {
		return PlaceDAO.format(this,true).replaceAll("\\s", "+");
	}
}
